package club.itstudio.itouc.config

import org.springframework.context.annotation.Configuration
import org.springframework.scheduling.annotation.AsyncConfigurer
import org.springframework.scheduling.annotation.EnableAsync
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor
import java.util.concurrent.Executor

@EnableAsync
@Configuration
class ThreadPoolConfig: AsyncConfigurer{
    val coreSize = 4        // 核心线程数
    val maxSize = 8         // 最大线程数
    val queueSize = 2500    // 队列数

    override fun getAsyncExecutor(): Executor? {
        val executor = ThreadPoolTaskExecutor()
        executor.corePoolSize = coreSize
        executor.maxPoolSize = maxSize
        executor.setQueueCapacity(queueSize)
        executor.setWaitForTasksToCompleteOnShutdown(true)
        executor.setAwaitTerminationSeconds(60 * 10)
        executor.setThreadNamePrefix("AsyncThread-")
        executor.initialize()
        return executor
    }

}